<?php

class generadorHTML {

    private static $instancia;

    public static function getInstance() {
        if (!self::$instancia instanceof self) {
            self::$instancia = new self;
        }
        return self::$instancia;
    }

    function cargar_combo($varform, $ancho, $margen, $defecto) {
        $res = "";

        $res.= '<select  style="width:' . $ancho . 'px; margin-left:' . $margen . 'px" id="' . $varform . '" >';
        if ($defecto == '1') {
            $res.= "<option value='1'>Administrador</option>\n";
            $res.= "<option value='2'>Ususario</option>\n";
        } elseif ($defecto == '2') {
            $res.= "<option value='2'>Ususario</option>\n";
            $res.= "<option value='1'>Administrador</option>\n";
        } else {
            $res.= "<option value=\"\">        </option>\n";
            $res.= "<option value='1'>Administrador</option>\n";
            $res.= "<option value='2'>Ususario</option>\n";
        }
        $res.= "</select>";
        return $res;
    }

    function cargar_combo2($tabla, $varform, $ancho, $campo, $margen, $defecto) {
        $res = "";

        if (count($tabla) != 0) {
            $res.= '<select  style="width:' . $ancho . 'px; margin-left:' . $margen . 'px" id="' . $varform . '">\n';
            $aux = 0;
            $x = 0;

            foreach ($tabla as $fila) {
                if ($aux == 0) {
                    if ($varform == 'deptos') {
                        if ($defecto != '') {
                            $auxiliar = 0;
                            foreach ($tabla as $fila2) {
                                foreach ($fila2->cocheras as $fila3) {
                                    if ($fila3->$campo == $defecto) {
                                        $auxiliar = 1;
                                    }
                                }
                                if ($auxiliar == 1) {
                                    $res.= "<option value=\"" . $fila2->iddepartamento . "\">" . $fila2 . "</option>\n";
                                    if ($fila->iddepartamento != $fila2->iddepartamento) {
                                        $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                                    }
                                    $x = 1;
                                    $auxiliar = 0;
                                }
                            }
                        } else {
                            $res.= "<option value=\"\">        </option>\n";
                            $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                        }
                    } else {
                        $res.= "<option value=\"\">        </option>\n";
                        $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                    }
                    if ($x == 0 && $defecto != '') {
                        $res.= "<option value=\"\">        </option>\n";
                        $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                    }
                    $aux = 1;
                } else {
                    if ($defecto != '') {
                        if (count($fila->cocheras) > 0) {
                            foreach ($fila->cocheras as $fila3) {
                                if ($fila3->$campo != $defecto) {
                                    $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                                }
                            }
                        } else {
                            $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                        }
                    } else {
                        $res.= "<option value=\"" . $fila->iddepartamento . "\">" . $fila . "</option>\n";
                    }
                }
            }
            $res.= "<option value=\"\">        </option>\n";
            $res.= "</select>";
        } else {
            $res.= '<select  style="width:' . $ancho . 'px; margin-left:' . $margen . 'px"  id="' . $varform . '" onchange="()">\n';
            $res.= "<option value=\"\"> No Existen Registros</option>\n";

            $res.= "</select>";
        }
        return $res;
    }

    function cargar_combo3($tabla, $varform, $ancho, $campo, $margen, $defecto) {
        $res = "";
        if (count($tabla) != 0) {
            $res.= '<select  style="width:' . $ancho . 'px; margin-left:' . $margen . 'px" id="' . $varform . '">\n';
            $aux = 0;
            $x = 0;
//            var_dump($tabla);

            foreach ($tabla as $fila) {
                if ($aux == 0) {
                    if ($varform == 'autos' || $varform == 'deptos') {
                        if ($defecto != '') {
                            foreach ($tabla as $fila2) {
                                if ($fila2->$campo == $defecto) {
                                    $res.= "<option value=\"" . $fila2->$campo . "\">" . $fila2 . "</option>\n";
                                    if ($fila->$campo != $fila2->$campo) {
                                        $res.= "<option value=\"" . $fila->$campo . "\">" . $fila . "</option>\n";
                                    }
                                    $x = 1;
                                }
                            }
                        } else {
                            $res.= "<option value=\"\">        </option>\n";
                            $res.= "<option value=\"" . $fila->$campo . "\">" . $fila . "</option>\n";
                        }
                    } else {
                        $res.= "<option value=\"\">        </option>\n";
                        $res.= "<option value=\"" . $fila->$campo . "\">" . $fila . "</option>\n";
                    }

                    $aux = 1;
                } else {
                    if ($defecto != '') {
                        if ($fila->$campo != $defecto) {
                            $res.= "<option value=\"" . $fila->$campo . "\">" . $fila . "</option>\n";
                        }
                    } else {
                        $res.= "<option value=\"" . $fila->$campo . "\">" . $fila . "</option>\n";
                    }
                }
            }
            $res.= "<option value=\"\">        </option>\n";
            $res.= "</select>";
        } else {
            $res.= '<select  style="width:' . $ancho . 'px; margin-left:' . $margen . 'px"  id="' . $varform . '" onchange="()">\n';
            $res.= "<option value=\"\"> No Existen Registros</option>\n";

            $res.= "</select>";
        }
        return $res;
    }

}

?>
